#!/bin/bash
########################################################################
# script name:  snap_cluster.sh
# Used for:
# Author:       Martin Dumont
# Contributors:
# Version:      0.1
#
# (date format: date +'%Y/%m/%d')
#
# Date          Version Contributors    Modifications
# ----------    ------- ------------    -------------
# 2012/01/30    0.1     MDUMONT         initial
########################################################################
BAENV=$(dirname `which $0`)/loadenv.sh
if [ -f $BAENV ]; then . $BAENV; else echo "No env library ($BAENV)"; exit 1; fi
CLUSTERDIR=$LOGDIR/cluster; if [ ! -d $CLUSTERDIR ]; then mkdir -m 755 -p $CLUSTERDIR; fi
ARCHIVEDIR=$CLUSTERDIR/archives
DIR=$CLUSTERDIR/`uname -n`
if [ ! -d $ARCHIVEDIR ]
then
        mkdir -m 755 -p $ARCHIVEDIR
else
        if cd $ARCHIVEDIR
        then
                ls -1td | grep $(uname -n) | tail -n +10 | xargs \rm -rf
        else
                echo "Cannot descent to $ARCHIVEDIR, exiting"
                exit 1
        fi
fi
if [ -d $DIR ]; then mv $DIR $ARCHIVEDIR/$(uname -n).`date +'%Y-%m-%d-%H-%M'`; fi
mkdir -p $DIR ; chown saunix $DIR
COMMANDDIR=/usr/es/sbin/cluster/utilities
COMMAND=cltopinfo; FILE=$DIR/$COMMAND.txt; if [ -x $COMMANDDIR/$COMMAND ]; then $COMMANDDIR/$COMMAND | sudo -u saunix tee $FILE 2>&1 > /dev/null; fi
COMMAND=clRGinfo; FILE=$DIR/`uname -n`.$COMMAND.txt; if [ -x $COMMANDDIR/$COMMAND ]; then $COMMANDDIR/$COMMAND | sudo -u saunix tee $FILE 2>&1 > /dev/null; fi
COMMAND=clsnapshotinfo; FILE=$DIR/`uname -n`.$COMMAND.txt; if [ -x $COMMANDDIR/$COMMAND ]; then $COMMANDDIR/$COMMAND | sudo -u saunix tee $FILE 2>&1 > /dev/null; fi
sudo -u saunix chmod -f 755 $DIR/`uname -n`.*.txt 2>&1 > /dev/null
########################################################################
exit 0
